<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="../config/config.jsp"%>
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="UTF-8">
<link rel="stylesheet" href="<%=basePath %>css/bootstrap.min.css" media="screen"/>
<link rel="stylesheet" href="<%=basePath %>css/bootstrap-datetimepicker.min.css" media="screen"/>
<link rel="stylesheet" href="<%=basePath %>css/bootstrap-theme.min.css" />

<script src="<%=basePath %>js/jquery-3.2.1.min.js"></script>
<script src="<%=basePath %>js/bootstrap.min.js"></script>
<script src="<%=basePath %>js/bootstrap-datetimepicker.js"></script>
<script src="<%=basePath %>js/locales/bootstrap-datetimepicker.zh-CN.js"></script>


<style type="text/css">
body {
	padding-bottom: 40px;
}

.sidebar-nav {
	padding: 9px 0;
}

@media ( max-width : 980px) {
	/* Enable use of floated navbar text */
	.navbar-text.pull-right {
		float: none;
		padding-left: 5px;
		padding-right: 5px;
	}
}

.table tr td {
	border: 1px solid transparent !important;
}

.form-control {
	width: 14%;
}
</style>
</head>
<body>
	<form action="" method="">
		<table class="table table-condensed">
			<tr>
				<td width="7%" style="line-height: 32px;">场次编号</td>
				<td><input type="text" name="sessionId" id="sessionId" class="form-control" value="${sessions.sessionId}" style="width:215px;"
					readonly /></td>
			</tr>
			<tr>
				<td style="width:7%;line-height: 32px;">场&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;厅</td>
				<td>
					<select name="hallId" id="hallId" class="selectpicker show-tick form-control" style="width: 215px;"
					data-live-search="false">
						<%
							List<Hall> HallList = (List<Hall>) request.getAttribute("HallList");
							for (int i = 0; i < HallList.size(); i++) {
								Hall m = HallList.get(i);
						%>
							<option value="<%=m.getHallId() %>"><%=m.getHallName() %></option>
						<%
							}
						%>	
					</select>
				</td>
			</tr>
			<tr>
			<td style="line-height: 32px;">影&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;片</td>
				<td>
					<select name="movieId" id="movieId" class="selectpicker show-tick form-control" style="width: 215px;"
					data-live-search="false">
						<%
							List<Movie> MovieList = (List<Movie>) request.getAttribute("MovieList");
							for (int i = 0; i < MovieList.size(); i++) {
								Movie m = MovieList.get(i);
						%>
							<option value="<%=m.getMovieId() %>"><%=m.getMovieName() %></option>
						<%
							}
						%>	
					</select>
				</td>
			</tr>
			<tr>
				<td style="line-height: 32px;">电影票价</td>
				<td><input type="text" name="price" id="price" value="${sessions.price}"
					class="form-control" style="width:215px;" required/>
				</td>
			</tr>
			<tr>
				<td style="line-height: 32px;">放映时间</td>
				<td>
					<div class="input-group date form_datetime col-md-5"  data-date-format="yyyy-mm-dd hh:ii:ss" style="width:215px;" data-link-field="dtp_input1">
	                    <input class="form-control" size="16" type="text" value="${sessions.time}" name="time" id="time" required readonly>
	                    <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
						<span class="input-group-addon"><span class="glyphicon glyphicon-th"></span></span>
	                </div>
	                <input type="hidden" id="dtp_input1" value="" />
				</td>
			</tr>
			<tr>
				<td></td>
				<td>
					<button type="button" class="btn btn-primary save">保 存</button>&nbsp;&nbsp;
					<button type="button" class="btn btn-success" name="backid"
						id="backid">返 回</button>
				</td>
			</tr>
		</table>
	</form>
</body>

<script>
	var newDate = new Date();
	var t = newDate.toJSON(); 
	$('.form_datetime').datetimepicker({
	    language:  'zh-CN',
	    weekStart: 1,
	    todayBtn:  1,
		autoclose: 1,
		todayHighlight: 1,
		startView: 2,
		forceParse: 0,
	    showMeridian: 1,
	    startDate:new Date(t)
	});
    $(function () {    
    	// 回显场厅下拉框数据
    	var hallId = "${sessions.hallId}";
    	$("#hallId").val(hallId);
    	
    	// 回显影片下拉框数据
    	var movieId = "${sessions.movieId}";
    	$("#movieId").val(movieId);
    	
    	$(".save").click(function(){
    		var params = {};
    		params.sessionId = $("#sessionId").val();
    		params.hallId = $("#hallId").val();
    		params.movieId = $("#movieId").val();
    		params.time = $("#time").val();
    		params.price = $("#price").val();
    		params.method = "update";
    		$.ajax({
    			url:"<%=basePath%>movieSessionServlet",
    			async: false, // 同步
		     	type: 'POST',
		     	data:params,
		     	success:function(data){
		     		if("error" == data){
			           alert("对不起，当前场厅正在进行影片播放！");
			        }else{
			        	window.location.href="Session/index.jsp";
			        }
		     	}
    		});
    		return false; // 取消默认行为
    	});
    	
		$('#backid').click(function(){
				window.location.href="Session/index.jsp";
		 });

    });
</script>
</html>